package kr.hkit.myframework.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//PDF 134p
public class DbUtil {
	
	public static void close(Connection con) {
		if(con != null) {
			try {
				con.close();
			} catch (SQLException e) {
				System.err.print(e);
			} finally { //확실하게 클로즈 
				con = null;
				System.out.println("MySQL Connection Close!!");
			}
		}
	}
	
	public static void close(PreparedStatement pstmt) {
		if(pstmt != null) {
			try {
				pstmt.close();
			} catch (SQLException e) {
				System.err.print(e);
			} finally { //확실하게 클로즈 
				pstmt = null;
			}
		}
	}
	
	public static void close(ResultSet rs) {
		if(rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				System.err.print(e);
			} finally { //확실하게 클로즈 
				rs = null;
			}
		}
	}
	
	
	public static void close(PreparedStatement pstmt, Connection con) {
		close(pstmt);
		close(con);
	}
	
	public static void close(ResultSet rs, PreparedStatement pstmt, 
			Connection con) {
		close(rs);
		close(pstmt, con);
	}
	
	//이건 왜 안됨??????
	/*public static void close(ResultSet rs, PreparedStatement pstmt) {
		close(rs, pstmt);   
	}*/ 
}
